#ifndef COMPONENTARGUMENTS_H
#define COMPONENTARGUMENTS_H


#include <map>
#include <string>

#include <boost/any.hpp>

#include "../OgreFrameWork.h"






class ComponentArguments
{
public:
    ComponentArguments();
    virtual ~ComponentArguments();


    void addArgument(std::string _name, std::string _value){addArgument<std::string>(_name,_value);}
    void addArgument(std::string _name, float _value){addArgument<float>(_name,_value);}
    void addArgument(std::string _name, int _value){addArgument<int>(_name,_value);}
    void addArgument(std::string _name, bool _value){addArgument<bool>(_name,_value);}
    void addArgument(std::string _name, Ogre::Vector3 _value){addArgument<Ogre::Vector3>(_name,_value);}

bool hasArgument(std::string _name){
    if(m_arguments.count(_name)>0) return true;
    else return false;}

    template < class T> void addArgument(std::string _name, T _value)
    {
        if (m_arguments.count(_name)==0)
        {
            m_arguments.insert(std::pair<std::string, boost::any>(_name,boost::any(_value)));
        }

    }


    template < class T> T getArgument(std::string _name)
    {


        T r;

        if (m_arguments.count(_name)>0)
        {

            try
            {
                r = boost::any_cast<T>(m_arguments[_name]);
            }
            catch(boost::bad_any_cast& bac) // nous attrapons l'exception
            {

                OgreFramework::getSingletonPtr()->m_pLog->logMessage("getArgument : "+_name +"   invalid type recquired");
            }

        }
        else
        {
            OgreFramework::getSingletonPtr()->m_pLog->logMessage("getArgument : no argument named "+_name +"   ");
            //return 0;
        }


        return r;
    }


protected:
private:

    std::map<std::string, boost::any> m_arguments;

};

#endif // COMPONENTARGUMENTS_H
